
$('#Commonheader').load('/pc/Commonheader.html');
$('#Commonfooter').load('/pc/CommonFooter.html');
	
$(function(){
	
	
	window.sessionStorage['type'] = 3;
	window.sessionStorage['pageNum'] = 1;
	
	initPage(3,1);
	
	$('#page').on('click','a:not(#page_list_num a)',function(e){
		e.preventDefault();
		$(this).addClass('active').parent().siblings().children('a.active').removeClass('active');
		$('#page_list_num').find('a.active').removeClass('active');
	})
	$('#page_list_num').on('click','a',function(e){
		e.preventDefault();
		$(this).addClass('active').parent().siblings().children('a.active').removeClass('active');
		$('#page').children().children('a.active').removeClass('active');
	})
	
	$('#aboutUs').on('click','li:not(:first-child)>a',function(e){
		e.preventDefault();
		
		$('#page').children().children('a.active').removeClass('active');
		var type = $(this).attr('data_type');
		window.sessionStorage['type'] = type;
		$(this).addClass('active').parent().siblings().children('a.active').removeClass('active');
		initPage(type,1);
	})
	
	//当点击固定页数时
	$('#page').on('click','li[pageNumType="fixed_page"]>a',function(e){
		e.preventDefault();
		var type = window.sessionStorage['type'];
		var page = $(this).attr('data_page');
		window.sessionStorage['pageNum'] = page;
		toPage(type,page);
	})
	//当点击上一页和下一页时
	$('#page').on('click','li[pageNumType="scroll_page"]>a',function(e){
		e.preventDefault();
		var type = window.sessionStorage['type'];
		var pageNum = window.sessionStorage['pageNum'];
		var page = 0;
		if($(this).attr('id') == 'prov'){
			if( pageNum > 1 ){
				page = Number(pageNum)-1;
				window.sessionStorage['pageNum'] = page;
				toPage(type,page);
			}
		}else{
			var last_pageNum = $('#last_page').attr('data_page');
			
			if( pageNum < last_pageNum ){
				page = Number(pageNum)+1;
				window.sessionStorage['pageNum'] = page;
				toPage(type,page);
			}
		}

	})
	
	function toPage(type,page){
		$.ajax({
			url:'/scoket/queryMsg',
			type:'get',
			data:{
				type:type,
				pageNow:page
			},
			success:function(data){
				var datas = data.list.list;
				var main_listHTML = ''; 
				for(var i=0;i<datas.length;i++){
					main_listHTML += `
						<li>
			                <div>
			                    <img src="${datas[i].imgSrc}" alt="图片加载中...">
			                </div>
			                <div>
			                    <p class="news_section_tip">${datas[i].title}</p>
			                    <p class="news_section_main">${datas[i].content}</p>
			                </div>
			            </li>
					`;
				}
				$('#main_list').html(main_listHTML);
			}
		})
	}
	
	function initPage(type,page){
		$.ajax({
			url:'/scoket/queryMsg',
			type:'get',
			data:{
				type:type,
				pageNow:page
			},
			success:function(data){
				var datas = data.list.list;
				var main_listHTML = '';
				for(var i=0;i<datas.length;i++){
					main_listHTML += `
						<li>
			                <div>
			                    <img src="${datas[i].imgSrc}" alt="图片加载中...">
			                </div>
			                <div>
			                    <p class="news_section_tip">${datas[i].title}</p>
			                    <p class="news_section_main">${datas[i].content}</p>
			                </div>
			            </li>
					`;
				}
				$('#main_list').html(main_listHTML);
				var page_list_numHTML='';
				if(data.list.totalPage ==1 ){
					page_list_numHTML='';
					page_list_numHTML += `
						<li pageNumType='fixed_page'><a href="" class="active" data_page='1'>01</a></li>
					`
				}
				if(data.list.totalPage ==2 ){
					page_list_numHTML='';
					page_list_numHTML += `
						<li pageNumType='fixed_page'><a href="" class="active" data_page='1'>01</a></li>
		                <li pageNumType='fixed_page'><a href="" data_page='2'>02</a></li>
					`
				}
				if(data.list.totalPage >=3 ){
					page_list_numHTML='';
					page_list_numHTML += `
						<li pageNumType='fixed_page'><a href="" class="active" data_page='1'>01</a></li>
		                <li pageNumType='fixed_page'><a href="" data_page='2'>02</a></li>
		                <li pageNumType='fixed_page'><a href="" data_page='3'>03</a></li>
					`
				}
				$('#page_list_num').html(page_list_numHTML);
				$('#last_page').attr('data_page',data.list.totalPage)
			}
		})
	}
	
})